package com.qianduo.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.qianduo.util.Global;

import net.sf.json.JSONObject;

import common.util.StringUtil;

public class QianduoServlet extends HttpServlet {
	private static final long serialVersionUID = -8290953568991947779L;

	public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{
		doPost(req,res);
	}
	
	public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{
		res.setContentType("text/html;charset=utf-8");
		PrintWriter out	= res.getWriter();
		String action	= StringUtil.isEmptyRetString(req.getParameter("action"));
		String page		= null;
		boolean redirect= false;
		
		if("getCities".equalsIgnoreCase(action)){
			JSONObject obj	= JSONObject.fromObject(Global.citiesMap);
			out.print(obj.toString());
		}else if("getAccountType".equalsIgnoreCase(action)){
			JSONObject obj	= JSONObject.fromObject(Global.accountTypeMap);
			out.print(obj.toString());
		}else if("getLoanType".equalsIgnoreCase(action)){
			JSONObject obj	= JSONObject.fromObject(Global.loanTypeMap);
			out.print(obj.toString());
		}else if("getProductType".equalsIgnoreCase(action)){
			JSONObject obj	= JSONObject.fromObject(Global.productTypeMap);
			out.print(obj.toString());
		}else if("getProfessionType".equalsIgnoreCase(action)){
			JSONObject obj	= JSONObject.fromObject(Global.professionTypeMap);
			out.print(obj.toString());
		}else if("getSexType".equalsIgnoreCase(action)){
			JSONObject obj	= JSONObject.fromObject(Global.sexTypeMap);
			out.print(obj.toString());
		}
		
		if(!StringUtil.isEmpty(page)){
			if(!redirect){
				RequestDispatcher dis	= req.getRequestDispatcher(page);
				dis.forward(req, res);
			}else{
				res.sendRedirect(page);
			}
		}
		out.flush();
		out.close();
	}
	
	
}
